local sk__gongxin = fk.CreateSkill {

  name = "sk__gongxin",

  tags = {},

}





sk__gongxin:addEffect("active", {
  name = "sk__gongxin",
  anim_type = "control",
  prompt = "#sk__gongxin",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(sk__gongxin.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and not to_select:isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local suits = { "log_spade", "log_heart", "log_club", "log_diamond" }
    local ids, _ = room:askToChooseCardsAndChoice(player,{
      cards=target:getCardIds("h"),
      choices={
        "OK"
      },
      skill_name=sk__gongxin.name,
      prompt="#sk__gongxin-prey::" .. target.id,
      cancel_choices={},
      min=1,max=1,
      all_cards=target:getCardIds("h")
    })
    local suit1 = Fk:getCardById(ids[1]):getSuitString(true)
    table.removeOne(suits, suit1)
    room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonPrey, sk__gongxin.name, nil, false, player)
    if target.dead then return end
    if not player.dead and not target:isKongcheng() then
      local cards2 = table.filter(target:getCardIds("h"), function(id)
        return Fk:getCardById(id):getSuitString(true) ~= suit1
      end)
      local n = #cards2 > 0 and 1 or 0
      local ids,_=room:askToChooseCardsAndChoice(player,{
        cards=cards2,
        choices={
          "OK"
        },
        skill_name=sk__gongxin.name,
        prompt="#sk__gongxin-discard::" .. target.id,
        cancel_choices={},
        min=n,max=1,
        all_cards=target:getCardIds("h")
      })
      if #ids > 0 then
        table.removeOne(suits, Fk:getCardById(ids[1]):getSuitString(true))
        room:throwCard(ids, sk__gongxin.name, target, player)
      end
    end
    if target.dead then return end
    room:setPlayerMark(target, "@sk__gongxin-turn", suits)
  end,
})

sk__gongxin:addEffect("prohibit", {
  name = "#sk__gongxin_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@sk__gongxin-turn") ~= 0 and card and
        table.contains(player:getMark("@sk__gongxin-turn"), card:getSuitString(true)) then
      local subcards = card:isVirtual() and card.subcards or { card.id }
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds("h"), id)
      end)
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@sk__gongxin-turn") ~= 0 and card and
        table.contains(player:getMark("@sk__gongxin-turn"), card:getSuitString(true)) then
      local subcards = card:isVirtual() and card.subcards or { card.id }
      return #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds("h"), id)
      end)
    end
  end,
})

return sk__gongxin
